Assembled by Thomas Tempelmann, rb@tempel.org, on Jan 21, 2001
Most simple way using MacsBug (Mac OS only)
I recommend this technique only to those who have some understanding of assembler and low-level system design. For those feeling uncomfortable digging that deep into the computer system, I suggest using one of the other two techniques below.
Install MacsBug (http://developer.apple.com/tools/debuggers/MacsBug/), Apple's resident machine language debugger, then insert statements that call the debugger into your source code, like this:
First, you need to include or declare the Debugger calls:
#ifndef WIN32
#include <MacMemory.h>
#else
#define Debugger() (void)
#define DebugStr(x) (void)
#endif
Then, you can use them like this:
long myFunc1 (long x)
{
DebugStr ("\pcalculating x*x");
x = x * x;
DebugStr ("\preturning the result");
return x;
}
Or, instead of using DebugStr with a text, you can use Debugger(), which does not take a string for display.
If you get into the debugger, use "G" (and Return) to have your code continue, or use "ES" to quit the active app, or use "RB" to restart your Mac if nothing else helps. Use "HELP" to get more information on MacsBug commands.
Alternate way using DCon (Mac) and DebugView (Windows)
DCon is a tool for the Mac OS that provides a floating window where you can print messages from your code using dprintf(), which is similar to the common "printf". DCon is a commercial product, available from http://www.devdepot.com/
Similarly, on Windows, you can write text messages via OutputDebugString() and make them visible with a free tool called DebugView, available from http://www.sysinternals.com/. There's also a Demo version of it on the latest CodeWarrior CDs (CW Pro 5 and later).
For your convenience, TT's Plugin Starter and some of the other Plugins by TT contain a macro definition that allows you to use log() to print simple text messages on both Mac and Windows.
If you want more sophisticated macros, check out Alfred Van Hoek's HTMLrendering Plugin, which contains a DCONPrefix.h file with lots more useful functions for this kind of logging. Plus, his plugin MongoToDCon provides the same logging functionality to RB applications. You can find it at: http://homepage.mac.com/vanhoek/
Most comfortable way using the CodeWarrior Debugger
Here's the steps to achieve this for a PPC plugin (idea by Ruslan Zasukhin, author of Valentina):
Set up the options for your plugin project in the CW IDE
I suggest to create a new target for that, by selecting the Targets tab in the project window, then choosing Create New Target... from the Project menu. There, name the new target something like "PPC debug", and choose the option Clone existing target, selecting your PPC or 68K target.
Now change the options for this target:
- Under the Project menu, choose Enable Debugger, confirming
any question to set up more options automatically for that.
- Next, choose the <your target name> Settings... under the
Edit menu. Make changes to the following panels:
- PPC Target (or 68K Target):
Update the following fields:
File Name: <fill in your plugin file name here>
Creator: RBv2
Type: RBPl
- Debugger Settings (called Runtime Settings in newer CW versions):
Use the Choose button to select the REALbasic application to
be launched for debugging of Code Resources.
- Target Settings:
Choose RB's "Plugins" folder as the Output Directory.
- Global Optimizations:
turn off any optimizations in order to avoid confusion
when using the debugger.
With these settings you can use the Run command on your new target. CW will then not only compile the plugin, but put it right into the plugins folder and then launch the REALbasic application.
Debugging your plugin
First, set breakpoints in your plugin's source code where desired.
Then choose Run (or Cmd-R) in the CW IDE. If everything goes well, REALbasic will be launched with an empty project.
Now open and run your REALbasic project that uses the plugin you are going to debug. Do not quit the CodeWarrior IDE.
Once your plugin code runs into one of your breakpoints, CW will present its debugging windows to you where you can start tracing and looking at the data.